# Replication code for Taylor C. Boas and Amy Erica Smith, “Looks Like Me, Thinks Like Me: Descriptive Representation and Opinion Congruence in Brazil.” Latin American Research Review 54, 2 (2019).

# Analysis conducted in R 3.6.0 on MacOS 10.13.6

# NOTE: This file replicates main text Figure 2, Appendix Figure 7, and Appendix Tables 11-12. It also replicates one result conveyed textually in the article. We recommend running R replication files in the following order; please see readme.txt for details.
# 	1_merge_lapop.R
# 	2_merge_latinobarometro.R
# 	3_recode_reshape.R
# 	4_difference_in_distributions.R
# 	5_regressions.R
# 	6_civil_society_meeting.R
# 	7_mass_descriptives.R
# 	8_elite_descriptives.R
# 	9_mean_differences.R
#	10_difference_in_distributions_ks.R
#	11_elite_sample_simulation.R
#	12_converts_vs_lifelong.R

# Set working directory as appropriate
# setwd('~/Dropbox/brazil_leg_surveys/replication/')

# Clean desktop and load packages. Please make sure all necessary packages are installed.

rm(list=ls(all=T))

library(lmtest)
library(sandwich)
library(Hmisc)
library(lattice)

load('dyads.RData')

# From http://people.su.se/~ma/clmclx.R, slightly modified to return the variance-covariance matrix
vcov.cluster <- 
function(fm, dfcw, cluster1, cluster2){
         # R-codes (www.r-project.org) for computing multi-way 
         # clustered-standard errors. Mahmood Arai, Jan 26, 2008. 
         # See: Thompson (2006), Cameron, Gelbach and Miller (2006)
         # and Petersen (2006).
	 # reweighting the var-cov matrix for the within model
         
         # The arguments of the function are:
         # fitted model, cluster1 and cluster2
         # You need to install libraries `sandwich' and `lmtest'
         
         library(sandwich);library(lmtest)
         cluster12 = paste(cluster1,cluster2, sep="")
         M1  <- length(unique(cluster1))
         M2  <- length(unique(cluster2))   
         M12 <- length(unique(cluster12))
         N   <- length(cluster1)          
         K   <- fm$rank             
         dfc1  <- (M1/(M1-1))*((N-1)/(N-K))  
         dfc2  <- (M2/(M2-1))*((N-1)/(N-K))  
         dfc12 <- (M12/(M12-1))*((N-1)/(N-K))  
         u1j   <- apply(estfun(fm), 2, function(x) tapply(x, cluster1,  sum)) 
         u2j   <- apply(estfun(fm), 2, function(x) tapply(x, cluster2,  sum)) 
         u12j  <- apply(estfun(fm), 2, function(x) tapply(x, cluster12, sum)) 
         vc1   <-  dfc1*sandwich(fm, meat=crossprod(u1j)/N )
         vc2   <-  dfc2*sandwich(fm, meat=crossprod(u2j)/N )
         vc12  <- dfc12*sandwich(fm, meat=crossprod(u12j)/N)
         vcovMCL <- (vc1 + vc2 - vc12)*dfcw
         vcovMCL}

# Variable for mass survey fixed effects
dyads$mass_survey<-factor(gsub('\\-.*','',dyads$mass_id))

dyads<-dyads[!is.na(dyads$elite_pweight),]

# ===================================================
# Indicators for any party match, any state match
# ===================================================

dyads$party_match<-dyads$elite_partythen==dyads$mass_party
dyads$party_match[is.na(dyads$party_match)]<-F
dyads$state_match<-dyads$elite_uf==dyads$mass_uf

# =======================
# Economic regime (all years, no Afro-Brazilian dummy variable)
# =======================

reg.econ.noblack.all.abs<-with(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','dyads_yweight','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight,formula=abs(elite_econ-mass_econ)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match))
vcov.econ.noblack.all.abs<-with(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','dyads_yweight','elite_pweight','mass_pweight')]), vcov.cluster(reg.econ.noblack.all.abs,1,mass_id,elite_id))
test.econ.noblack.all.abs<-coeftest(reg.econ.noblack.all.abs, vcov.econ.noblack.all.abs)
rm(reg.econ.noblack.all.abs)

reg.econ.noblack.multi.abs<-with(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight,formula=abs(elite_econ-mass_econ)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + mass_age + mass_news + mass_survey + mass_log.muni.pop + elite_years + elite_donations.norm + elite_clientelism))
vcov.econ.noblack.multi.abs<-with(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight','elite_pweight','mass_pweight')]), vcov.cluster(reg.econ.noblack.multi.abs,1,mass_id,elite_id))
test.econ.noblack.multi.abs<-coeftest(reg.econ.noblack.multi.abs, vcov.econ.noblack.multi.abs)
rm(reg.econ.noblack.multi.abs)

n.econ.noblack.all<-nrow(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','dyads_yweight','elite_pweight','mass_pweight')]))
n.elite.econ.noblack.all<-length(unique(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','dyads_yweight','elite_pweight','mass_pweight')])$elite_id))
n.mass.econ.noblack.all<-length(unique(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','dyads_yweight','elite_pweight','mass_pweight')])$mass_id))
n.econ.noblack.multi<-nrow(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight','elite_pweight','mass_pweight')]))
n.elite.econ.noblack.multi<-length(unique(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight','elite_pweight','mass_pweight')])$elite_id))
n.mass.econ.noblack.multi<-length(unique(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight','elite_pweight','mass_pweight')])$mass_id))

# =======================
# Ideology (all years, no Afro-Brazilian dummy variable)
# =======================

reg.ideol.noblack.all.abs<-with(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','dyads_yweight','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight,formula=abs(elite_ideol-mass_ideol)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match))
vcov.ideol.noblack.all.abs<-with(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','dyads_yweight','elite_pweight','mass_pweight')]), vcov.cluster(reg.ideol.noblack.all.abs,1,mass_id,elite_id))
test.ideol.noblack.all.abs<-coeftest(reg.ideol.noblack.all.abs, vcov.ideol.noblack.all.abs)
rm(reg.ideol.noblack.all.abs)

reg.ideol.noblack.multi.abs<-with(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight,formula=abs(elite_ideol-mass_ideol)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + mass_age + mass_news + mass_survey + mass_log.muni.pop + elite_years + elite_donations.norm + elite_clientelism))
vcov.ideol.noblack.multi.abs<-with(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight','elite_pweight','mass_pweight')]), vcov.cluster(reg.ideol.noblack.multi.abs,1,mass_id,elite_id))
test.ideol.noblack.multi.abs<-coeftest(reg.ideol.noblack.multi.abs, vcov.ideol.noblack.multi.abs)
rm(reg.ideol.noblack.multi.abs)

n.ideol.noblack.all<-nrow(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','dyads_yweight','elite_pweight','mass_pweight')]))
n.elite.ideol.noblack.all<-length(unique(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','dyads_yweight','elite_pweight','mass_pweight')])$elite_id))
n.mass.ideol.noblack.all<-length(unique(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','dyads_yweight','elite_pweight','mass_pweight')])$mass_id))
n.ideol.noblack.multi<-nrow(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight','elite_pweight','mass_pweight')]))
n.elite.ideol.noblack.multi<-length(unique(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight','elite_pweight','mass_pweight')])$elite_id))
n.mass.ideol.noblack.multi<-length(unique(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight','elite_pweight','mass_pweight')])$mass_id))

# =======================
# Economic regime (2007-13, with Afro-Brazilian dummy variable)
# =======================

reg.econ.all.abs<-with(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_econ-mass_econ)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black)))
vcov.econ.all.abs<-with(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.econ.all.abs,1,mass_id,elite_id))
test.econ.all.abs<-coeftest(reg.econ.all.abs, vcov.econ.all.abs)
rm(reg.econ.all.abs)

reg.econ.multi.abs<-with(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_econ-mass_econ)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black) + mass_age + mass_news + mass_survey + mass_log.muni.pop + elite_years + elite_donations.norm + elite_clientelism))
vcov.econ.multi.abs<-with(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.econ.multi.abs,1,mass_id,elite_id))
test.econ.multi.abs<-coeftest(reg.econ.multi.abs, vcov.econ.multi.abs)
rm(reg.econ.multi.abs)

n.econ.all<-nrow(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.econ.all<-length(unique(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.econ.all<-length(unique(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))
n.econ.multi<-nrow(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.econ.multi<-length(unique(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.econ.multi<-length(unique(na.exclude(dyads[,c('elite_econ','mass_econ','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))

# =======================
# Ideology (2007-13, with Afro-Brazilian dummy variable)
# =======================

reg.ideol.all.abs<-with(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_ideol-mass_ideol)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black)))
vcov.ideol.all.abs<-with(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.ideol.all.abs,1,mass_id,elite_id))
test.ideol.all.abs<-coeftest(reg.ideol.all.abs, vcov.ideol.all.abs)
rm(reg.ideol.all.abs)

reg.ideol.multi.abs<-with(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_ideol-mass_ideol)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black) + mass_age + mass_news + mass_survey + mass_log.muni.pop + elite_years + elite_donations.norm + elite_clientelism))
vcov.ideol.multi.abs<-with(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.ideol.multi.abs,1,mass_id,elite_id))
test.ideol.multi.abs<-coeftest(reg.ideol.multi.abs, vcov.ideol.multi.abs)
rm(reg.ideol.multi.abs)

n.ideol.all<-nrow(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.ideol.all<-length(unique(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.ideol.all<-length(unique(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))
n.ideol.multi<-nrow(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.ideol.multi<-length(unique(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.ideol.multi<-length(unique(na.exclude(dyads[,c('elite_ideol','mass_ideol','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))

# =======================
# Gay Marriage
# =======================

reg.gaymarriage.all.abs<-with(na.exclude(dyads[,c('elite_gaymarriage','mass_gaymarriage','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_gaymarriage-mass_gaymarriage)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black)))
vcov.gaymarriage.all.abs<-with(na.exclude(dyads[,c('elite_gaymarriage','mass_gaymarriage','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.gaymarriage.all.abs,1,mass_id,elite_id))
test.gaymarriage.all.abs<-coeftest(reg.gaymarriage.all.abs, vcov.gaymarriage.all.abs)
rm(reg.gaymarriage.all.abs)

reg.gaymarriage.multi.abs<-with(na.exclude(dyads[,c('elite_gaymarriage','mass_gaymarriage','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_gaymarriage-mass_gaymarriage)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black) + mass_age + mass_news + mass_survey + mass_log.muni.pop + elite_years + elite_donations.norm + elite_clientelism))
vcov.gaymarriage.multi.abs<-with(na.exclude(dyads[,c('elite_gaymarriage','mass_gaymarriage','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.gaymarriage.multi.abs,1,mass_id,elite_id))
test.gaymarriage.multi.abs<-coeftest(reg.gaymarriage.multi.abs, vcov.gaymarriage.multi.abs)
rm(reg.gaymarriage.multi.abs)

n.gaymarriage.all<-nrow(na.exclude(dyads[,c('elite_gaymarriage','mass_gaymarriage','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.gaymarriage.all<-length(unique(na.exclude(dyads[,c('elite_gaymarriage','mass_gaymarriage','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.gaymarriage.all<-length(unique(na.exclude(dyads[,c('elite_gaymarriage','mass_gaymarriage','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))
n.gaymarriage.multi<-nrow(na.exclude(dyads[,c('elite_gaymarriage','mass_gaymarriage','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.gaymarriage.multi<-length(unique(na.exclude(dyads[,c('elite_gaymarriage','mass_gaymarriage','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.gaymarriage.multi<-length(unique(na.exclude(dyads[,c('elite_gaymarriage','mass_gaymarriage','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_survey','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))

# =======================
# Affirmative Action
# =======================

reg.affirm.all.abs<-with(na.exclude(dyads[,c('elite_affirm','mass_affirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_affirm-mass_affirm)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black)))
vcov.affirm.all.abs<-with(na.exclude(dyads[,c('elite_affirm','mass_affirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.affirm.all.abs,1,mass_id,elite_id))
test.affirm.all.abs<-coeftest(reg.affirm.all.abs, vcov.affirm.all.abs)
rm(reg.affirm.all.abs)

reg.affirm.multi.abs<-with(na.exclude(dyads[,c('elite_affirm','mass_affirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_affirm-mass_affirm)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black) + mass_age + mass_news + mass_log.muni.pop + elite_years + elite_donations.norm + elite_clientelism))
vcov.affirm.multi.abs<-with(na.exclude(dyads[,c('elite_affirm','mass_affirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.affirm.multi.abs,1,mass_id,elite_id))
test.affirm.multi.abs<-coeftest(reg.affirm.multi.abs, vcov.affirm.multi.abs)
rm(reg.affirm.multi.abs)

n.affirm.all<-nrow(na.exclude(dyads[,c('elite_affirm','mass_affirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.affirm.all<-length(unique(na.exclude(dyads[,c('elite_affirm','mass_affirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.affirm.all<-length(unique(na.exclude(dyads[,c('elite_affirm','mass_affirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))
n.affirm.multi<-nrow(na.exclude(dyads[,c('elite_affirm','mass_affirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.affirm.multi<-length(unique(na.exclude(dyads[,c('elite_affirm','mass_affirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.affirm.multi<-length(unique(na.exclude(dyads[,c('elite_affirm','mass_affirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))

# =======================
# Abortion 
# =======================

reg.abortion.all.abs<-with(na.exclude(dyads[,c('elite_abortion','mass_abortion','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_abortion-mass_abortion)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black)))
vcov.abortion.all.abs<-with(na.exclude(dyads[,c('elite_abortion','mass_abortion','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.abortion.all.abs,1,mass_id,elite_id))
test.abortion.all.abs<-coeftest(reg.abortion.all.abs, vcov.abortion.all.abs)
rm(reg.abortion.all.abs)

reg.abortion.multi.abs<-with(na.exclude(dyads[,c('elite_abortion','mass_abortion','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_abortion-mass_abortion)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black) + mass_age + mass_news + mass_log.muni.pop + elite_years + elite_donations.norm + elite_clientelism))
vcov.abortion.multi.abs<-with(na.exclude(dyads[,c('elite_abortion','mass_abortion','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.abortion.multi.abs,1,mass_id,elite_id))
test.abortion.multi.abs<-coeftest(reg.abortion.multi.abs, vcov.abortion.multi.abs)
rm(reg.abortion.multi.abs)

n.abortion.all<-nrow(na.exclude(dyads[,c('elite_abortion','mass_abortion','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.abortion.all<-length(unique(na.exclude(dyads[,c('elite_abortion','mass_abortion','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.abortion.all<-length(unique(na.exclude(dyads[,c('elite_abortion','mass_abortion','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))
n.abortion.multi<-nrow(na.exclude(dyads[,c('elite_abortion','mass_abortion','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.abortion.multi<-length(unique(na.exclude(dyads[,c('elite_abortion','mass_abortion','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.abortion.multi<-length(unique(na.exclude(dyads[,c('elite_abortion','mass_abortion','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))

# =======================
# Class Affirmative Action 
# =======================

reg.classaffirm.all.abs<-with(na.exclude(dyads[,c('elite_classaffirm','mass_classaffirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_classaffirm-mass_classaffirm)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black)))
vcov.classaffirm.all.abs<-with(na.exclude(dyads[,c('elite_classaffirm','mass_classaffirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.classaffirm.all.abs,1,mass_id,elite_id))
test.classaffirm.all.abs<-coeftest(reg.classaffirm.all.abs, vcov.classaffirm.all.abs)
rm(reg.classaffirm.all.abs)

reg.classaffirm.multi.abs<-with(na.exclude(dyads[,c('elite_classaffirm','mass_classaffirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_classaffirm-mass_classaffirm)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black) + mass_age + mass_news + mass_log.muni.pop + elite_years + elite_donations.norm + elite_clientelism))
vcov.classaffirm.multi.abs<-with(na.exclude(dyads[,c('elite_classaffirm','mass_classaffirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.classaffirm.multi.abs,1,mass_id,elite_id))
test.classaffirm.multi.abs<-coeftest(reg.classaffirm.multi.abs, vcov.classaffirm.multi.abs)
rm(reg.classaffirm.multi.abs)

n.classaffirm.all<-nrow(na.exclude(dyads[,c('elite_classaffirm','mass_classaffirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.classaffirm.all<-length(unique(na.exclude(dyads[,c('elite_classaffirm','mass_classaffirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.classaffirm.all<-length(unique(na.exclude(dyads[,c('elite_classaffirm','mass_classaffirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))
n.classaffirm.multi<-nrow(na.exclude(dyads[,c('elite_classaffirm','mass_classaffirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.classaffirm.multi<-length(unique(na.exclude(dyads[,c('elite_classaffirm','mass_classaffirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.classaffirm.multi<-length(unique(na.exclude(dyads[,c('elite_classaffirm','mass_classaffirm','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))

# =======================
# Environment 
# =======================

reg.environment.all.abs<-with(na.exclude(dyads[,c('elite_environment','mass_environment','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_environment-mass_environment)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black)))
vcov.environment.all.abs<-with(na.exclude(dyads[,c('elite_environment','mass_environment','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.environment.all.abs,1,mass_id,elite_id))
test.environment.all.abs<-coeftest(reg.environment.all.abs, vcov.environment.all.abs)
rm(reg.environment.all.abs)

reg.environment.multi.abs<-with(na.exclude(dyads[,c('elite_environment','mass_environment','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]),lm(weights=elite_pweight*mass_pweight*dyads_yweight.black,formula=abs(elite_environment-mass_environment)~I(elite_evang*mass_evang) + I(elite_female*mass_female) + I(elite_loweduc*mass_loweduc) + party_match + state_match + I(elite_black*mass_black) + mass_age + mass_news + mass_log.muni.pop + elite_years + elite_donations.norm + elite_clientelism))
vcov.environment.multi.abs<-with(na.exclude(dyads[,c('elite_environment','mass_environment','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]), vcov.cluster(reg.environment.multi.abs,1,mass_id,elite_id))
test.environment.multi.abs<-coeftest(reg.environment.multi.abs, vcov.environment.multi.abs)
rm(reg.environment.multi.abs)

n.environment.all<-nrow(na.exclude(dyads[,c('elite_environment','mass_environment','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.environment.all<-length(unique(na.exclude(dyads[,c('elite_environment','mass_environment','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.environment.all<-length(unique(na.exclude(dyads[,c('elite_environment','mass_environment','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))
n.environment.multi<-nrow(na.exclude(dyads[,c('elite_environment','mass_environment','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')]))
n.elite.environment.multi<-length(unique(na.exclude(dyads[,c('elite_environment','mass_environment','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$elite_id))
n.mass.environment.multi<-length(unique(na.exclude(dyads[,c('elite_environment','mass_environment','elite_evang','mass_evang','mass_id','elite_id','elite_female','mass_female','elite_loweduc','mass_loweduc','party_match','state_match','elite_black','mass_black','mass_age','mass_news','mass_log.muni.pop','elite_years','elite_donations.norm','elite_clientelism','dyads_yweight.black','elite_pweight','mass_pweight')])$mass_id))

rm(dyads)

# ========================================================================
# Appendix Table 11: Congruence: WLS Regression Results
# Appendix Table 12: Congruence: WLS Regression Results (Without Controls)
# ========================================================================

beta.econ.all.abs<-round(c(test.econ.all.abs[-1,'Estimate'][c(1:3,6,4:5)],rep(NA,6)),3)
se.econ.all.abs<-round(c(test.econ.all.abs[-1,'Std. Error'][c(1:3,6,4:5)],rep(NA,6)),3)
pval.econ.all.abs<-c(test.econ.all.abs[-1,'Pr(>|t|)'][c(1:3,6,4:5)],rep(NA,6))
stars.econ.all.abs<-rep('\\ \\ \\ ',length(beta.econ.all.abs))
stars.econ.all.abs[pval.econ.all.abs <.1]<-'$\\dagger$\\ \\ '
stars.econ.all.abs[pval.econ.all.abs <.05]<-'$^*$\\ \\ '
stars.econ.all.abs[pval.econ.all.abs <.01]<-'$^{**}$\\ '
stars.econ.all.abs[pval.econ.all.abs <.001]<-'$^{***}$'
beta.econ.all.abs<-ifelse(is.na(beta.econ.all.abs),'', paste(beta.econ.all.abs, stars.econ.all.abs,sep=''))
se.econ.all.abs<-ifelse(is.na(se.econ.all.abs),'',paste('(', se.econ.all.abs,')\\ \\ ',sep=''))
econ.all.abs<-c(as.vector(rbind(beta.econ.all.abs, se.econ.all.abs)),formatC(c(n.econ.all,n.elite.econ.all,n.mass.econ.all),big.mark=',',format='d'))

beta.econ.multi.abs<-round(c(test.econ.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.econ.multi.abs)),'Estimate'][c(1:3,6,4:5,7:12)]),3)
se.econ.multi.abs<-round(c(test.econ.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.econ.multi.abs)),'Std. Error'][c(1:3,6,4:5,7:12)]),3)
pval.econ.multi.abs<-c(test.econ.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.econ.multi.abs)),'Pr(>|t|)'][c(1:3,6,4:5,7:12)])
stars.econ.multi.abs<-rep('\\ \\ \\ ',length(beta.econ.multi.abs))
stars.econ.multi.abs[pval.econ.multi.abs <.1]<-'$\\dagger$\\ \\ '
stars.econ.multi.abs[pval.econ.multi.abs <.05]<-'$^*$\\ \\ '
stars.econ.multi.abs[pval.econ.multi.abs <.01]<-'$^{**}$\\ '
stars.econ.multi.abs[pval.econ.multi.abs <.001]<-'$^{***}$'
beta.econ.multi.abs<-ifelse(is.na(beta.econ.multi.abs),'', paste(beta.econ.multi.abs, stars.econ.multi.abs,sep=''))
se.econ.multi.abs<-ifelse(is.na(se.econ.multi.abs),'',paste('(', se.econ.multi.abs,')\\ \\ ',sep=''))
econ.multi.abs<-c(as.vector(rbind(beta.econ.multi.abs, se.econ.multi.abs)),formatC(c(n.econ.multi,n.elite.econ.multi,n.mass.econ.multi),big.mark=',',format='d'))

beta.econ.noblack.all.abs<-round(c(test.econ.noblack.all.abs[-1,'Estimate'][1:3],NA, test.econ.noblack.all.abs[-1,'Estimate'][4:5],rep(NA,6)),3)
se.econ.noblack.all.abs<-round(c(test.econ.noblack.all.abs[-1,'Std. Error'][1:3],NA, test.econ.noblack.all.abs[-1,'Std. Error'][4:5],rep(NA,6)),3)
pval.econ.noblack.all.abs<-c(test.econ.noblack.all.abs[-1,'Pr(>|t|)'][1:3],NA, test.econ.noblack.all.abs[-1,'Pr(>|t|)'][4:5],rep(NA,6))
stars.econ.noblack.all.abs<-rep('\\ \\ \\ ',length(beta.econ.noblack.all.abs))
stars.econ.noblack.all.abs[pval.econ.noblack.all.abs <.1]<-'$\\dagger$\\ \\ '
stars.econ.noblack.all.abs[pval.econ.noblack.all.abs <.05]<-'$^*$\\ \\ '
stars.econ.noblack.all.abs[pval.econ.noblack.all.abs <.01]<-'$^{**}$\\ '
stars.econ.noblack.all.abs[pval.econ.noblack.all.abs <.001]<-'$^{***}$'
beta.econ.noblack.all.abs<-ifelse(is.na(beta.econ.noblack.all.abs),'', paste(beta.econ.noblack.all.abs, stars.econ.noblack.all.abs,sep=''))
se.econ.noblack.all.abs<-ifelse(is.na(se.econ.noblack.all.abs),'',paste('(', se.econ.noblack.all.abs,')\\ \\ ',sep=''))
econ.noblack.all.abs<-c(as.vector(rbind(beta.econ.noblack.all.abs, se.econ.noblack.all.abs)),formatC(c(n.econ.noblack.all,n.elite.econ.noblack.all,n.mass.econ.noblack.all),big.mark=',',format='d'))

beta.econ.noblack.multi.abs<-round(c(test.econ.noblack.multi.abs[2:4,'Estimate'], NA, test.econ.noblack.multi.abs[c(5:8,20:23),'Estimate']),3)
se.econ.noblack.multi.abs<-round(c(test.econ.noblack.multi.abs[2:4,'Std. Error'], NA, test.econ.noblack.multi.abs[c(5:8,20:23),'Std. Error']),3)
pval.econ.noblack.multi.abs<-c(test.econ.noblack.multi.abs[2:4,'Pr(>|t|)'], NA, test.econ.noblack.multi.abs[c(5:8,20:23),'Pr(>|t|)'],NA)
stars.econ.noblack.multi.abs<-rep('\\ \\ \\ ',length(beta.econ.noblack.multi.abs))
stars.econ.noblack.multi.abs[pval.econ.noblack.multi.abs <.1]<-'$\\dagger$\\ \\ '
stars.econ.noblack.multi.abs[pval.econ.noblack.multi.abs <.05]<-'$^*$\\ \\ '
stars.econ.noblack.multi.abs[pval.econ.noblack.multi.abs <.01]<-'$^{**}$\\ '
stars.econ.noblack.multi.abs[pval.econ.noblack.multi.abs <.001]<-'$^{***}$'
beta.econ.noblack.multi.abs<-ifelse(is.na(beta.econ.noblack.multi.abs),'', paste(beta.econ.noblack.multi.abs, stars.econ.noblack.multi.abs,sep=''))
se.econ.noblack.multi.abs<-ifelse(is.na(se.econ.noblack.multi.abs),'',paste('(', se.econ.noblack.multi.abs,')\\ \\ ',sep=''))
econ.noblack.multi.abs<-c(as.vector(rbind(beta.econ.noblack.multi.abs, se.econ.noblack.multi.abs)),formatC(c(n.econ.noblack.multi,n.elite.econ.noblack.multi,n.mass.econ.noblack.multi),big.mark=',',format='d'))

beta.ideol.all.abs<-round(c(test.ideol.all.abs[-1,'Estimate'][c(1:3,6,4:5)],rep(NA,6)),3)
se.ideol.all.abs<-round(c(test.ideol.all.abs[-1,'Std. Error'][c(1:3,6,4:5)],rep(NA,6)),3)
pval.ideol.all.abs<-c(test.ideol.all.abs[-1,'Pr(>|t|)'][c(1:3,6,4:5)],rep(NA,6))
stars.ideol.all.abs<-rep('\\ \\ \\ ',length(beta.ideol.all.abs))
stars.ideol.all.abs[pval.ideol.all.abs <.1]<-'$\\dagger$\\ \\ '
stars.ideol.all.abs[pval.ideol.all.abs <.05]<-'$^*$\\ \\ '
stars.ideol.all.abs[pval.ideol.all.abs <.01]<-'$^{**}$\\ '
stars.ideol.all.abs[pval.ideol.all.abs <.001]<-'$^{***}$'
beta.ideol.all.abs<-ifelse(is.na(beta.ideol.all.abs),'', paste(beta.ideol.all.abs, stars.ideol.all.abs,sep=''))
se.ideol.all.abs<-ifelse(is.na(se.ideol.all.abs),'',paste('(', se.ideol.all.abs,')\\ \\ ',sep=''))
ideol.all.abs<-c(as.vector(rbind(beta.ideol.all.abs, se.ideol.all.abs)),formatC(c(n.ideol.all,n.elite.ideol.all,n.mass.ideol.all),big.mark=',',format='d'))

beta.ideol.multi.abs<-round(c(test.ideol.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.ideol.multi.abs)),'Estimate'][c(1:3,6,4:5,7:12)]),3)
se.ideol.multi.abs<-round(c(test.ideol.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.ideol.multi.abs)),'Std. Error'][c(1:3,6,4:5,7:12)]),3)
pval.ideol.multi.abs<-c(test.ideol.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.ideol.multi.abs)),'Pr(>|t|)'][c(1:3,6,4:5,7:12)])
stars.ideol.multi.abs<-rep('\\ \\ \\ ',length(beta.ideol.multi.abs))
stars.ideol.multi.abs[pval.ideol.multi.abs <.1]<-'$\\dagger$\\ \\ '
stars.ideol.multi.abs[pval.ideol.multi.abs <.05]<-'$^*$\\ \\ '
stars.ideol.multi.abs[pval.ideol.multi.abs <.01]<-'$^{**}$\\ '
stars.ideol.multi.abs[pval.ideol.multi.abs <.001]<-'$^{***}$'
beta.ideol.multi.abs<-ifelse(is.na(beta.ideol.multi.abs),'', paste(beta.ideol.multi.abs, stars.ideol.multi.abs,sep=''))
se.ideol.multi.abs<-ifelse(is.na(se.ideol.multi.abs),'',paste('(', se.ideol.multi.abs,')\\ \\ ',sep=''))
ideol.multi.abs<-c(as.vector(rbind(beta.ideol.multi.abs, se.ideol.multi.abs)),formatC(c(n.ideol.multi,n.elite.ideol.multi,n.mass.ideol.multi),big.mark=',',format='d'))

beta.ideol.noblack.all.abs<-round(c(test.ideol.noblack.all.abs[2:4,'Estimate'],NA, test.ideol.noblack.all.abs[5:6,'Estimate'], rep(NA,6)),3)
se.ideol.noblack.all.abs<-round(c(test.ideol.noblack.all.abs[2:4,'Std. Error'],NA, test.ideol.noblack.all.abs[5:6,'Std. Error'], rep(NA,6)),3)
pval.ideol.noblack.all.abs<-c(test.ideol.noblack.all.abs[2:4,'Pr(>|t|)'],NA, test.ideol.noblack.all.abs[5:6,'Pr(>|t|)'], rep(NA,6))
stars.ideol.noblack.all.abs<-rep('\\ \\ \\ ',length(beta.ideol.noblack.all.abs))
stars.ideol.noblack.all.abs[pval.ideol.noblack.all.abs <.1]<-'$\\dagger$\\ \\ '
stars.ideol.noblack.all.abs[pval.ideol.noblack.all.abs <.05]<-'$^*$\\ \\ '
stars.ideol.noblack.all.abs[pval.ideol.noblack.all.abs <.01]<-'$^{**}$\\ '
stars.ideol.noblack.all.abs[pval.ideol.noblack.all.abs <.001]<-'$^{***}$'
beta.ideol.noblack.all.abs<-ifelse(is.na(beta.ideol.noblack.all.abs),'', paste(beta.ideol.noblack.all.abs, stars.ideol.noblack.all.abs,sep=''))
se.ideol.noblack.all.abs<-ifelse(is.na(se.ideol.noblack.all.abs),'',paste('(', se.ideol.noblack.all.abs,')\\ \\ ',sep=''))
ideol.noblack.all.abs<-c(as.vector(rbind(beta.ideol.noblack.all.abs, se.ideol.noblack.all.abs)),formatC(c(n.ideol.noblack.all,n.elite.ideol.noblack.all,n.mass.ideol.noblack.all),big.mark=',',format='d'))

beta.ideol.noblack.multi.abs<-round(c(test.ideol.noblack.multi.abs[2:4,'Estimate'], NA, test.ideol.noblack.multi.abs[c(5:8,23:26),'Estimate']),3)
se.ideol.noblack.multi.abs<-round(c(test.ideol.noblack.multi.abs[2:4,'Std. Error'], NA, test.ideol.noblack.multi.abs[c(5:8,23:26),'Std. Error']),3)
pval.ideol.noblack.multi.abs<-c(test.ideol.noblack.multi.abs[2:4,'Pr(>|t|)'], NA, test.ideol.noblack.multi.abs[c(5:8,23:26),'Pr(>|t|)'])
stars.ideol.noblack.multi.abs<-rep('\\ \\ \\ ',length(beta.ideol.noblack.multi.abs))
stars.ideol.noblack.multi.abs[pval.ideol.noblack.multi.abs <.1]<-'$\\dagger$\\ \\ '
stars.ideol.noblack.multi.abs[pval.ideol.noblack.multi.abs <.05]<-'$^*$\\ \\ '
stars.ideol.noblack.multi.abs[pval.ideol.noblack.multi.abs <.01]<-'$^{**}$\\ '
stars.ideol.noblack.multi.abs[pval.ideol.noblack.multi.abs <.001]<-'$^{***}$'
beta.ideol.noblack.multi.abs<-ifelse(is.na(beta.ideol.noblack.multi.abs),'', paste(beta.ideol.noblack.multi.abs, stars.ideol.noblack.multi.abs,sep=''))
se.ideol.noblack.multi.abs<-ifelse(is.na(se.ideol.noblack.multi.abs),'',paste('(', se.ideol.noblack.multi.abs,')\\ \\ ',sep=''))
ideol.noblack.multi.abs<-c(as.vector(rbind(beta.ideol.noblack.multi.abs, se.ideol.noblack.multi.abs)),formatC(c(n.ideol.noblack.multi,n.elite.ideol.noblack.multi,n.mass.ideol.noblack.multi),big.mark=',',format='d'))

beta.affirm.all.abs<-round(c(test.affirm.all.abs[-1,'Estimate'][c(1:3,6,4:5)],rep(NA,6)),3)
se.affirm.all.abs<-round(c(test.affirm.all.abs[-1,'Std. Error'][c(1:3,6,4:5)],rep(NA,6)),3)
pval.affirm.all.abs<-c(test.affirm.all.abs[-1,'Pr(>|t|)'][c(1:3,6,4:5)],rep(NA,6))
stars.affirm.all.abs<-rep('\\ \\ \\ ',length(beta.affirm.all.abs))
stars.affirm.all.abs[pval.affirm.all.abs <.1]<-'$\\dagger$\\ \\ '
stars.affirm.all.abs[pval.affirm.all.abs <.05]<-'$^*$\\ \\ '
stars.affirm.all.abs[pval.affirm.all.abs <.01]<-'$^{**}$\\ '
stars.affirm.all.abs[pval.affirm.all.abs <.001]<-'$^{***}$'
beta.affirm.all.abs<-ifelse(is.na(beta.affirm.all.abs),'', paste(beta.affirm.all.abs, stars.affirm.all.abs,sep=''))
se.affirm.all.abs<-ifelse(is.na(se.affirm.all.abs),'',paste('(', se.affirm.all.abs,')\\ \\ ',sep=''))
affirm.all.abs<-c(as.vector(rbind(beta.affirm.all.abs, se.affirm.all.abs)),formatC(c(n.affirm.all,n.elite.affirm.all,n.mass.affirm.all),big.mark=',',format='d'))

beta.affirm.multi.abs<-round(c(test.affirm.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.affirm.multi.abs)),'Estimate'][c(1:3,6,4:5,7:12)]),3)
se.affirm.multi.abs<-round(c(test.affirm.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.affirm.multi.abs)),'Std. Error'][c(1:3,6,4:5,7:12)]),3)
pval.affirm.multi.abs<-c(test.affirm.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.affirm.multi.abs)),'Pr(>|t|)'][c(1:3,6,4:5,7:12)])
stars.affirm.multi.abs<-rep('\\ \\ \\ ',length(beta.affirm.multi.abs))
stars.affirm.multi.abs[pval.affirm.multi.abs <.1]<-'$\\dagger$\\ \\ '
stars.affirm.multi.abs[pval.affirm.multi.abs <.05]<-'$^*$\\ \\ '
stars.affirm.multi.abs[pval.affirm.multi.abs <.01]<-'$^{**}$\\ '
stars.affirm.multi.abs[pval.affirm.multi.abs <.001]<-'$^{***}$'
beta.affirm.multi.abs<-ifelse(is.na(beta.affirm.multi.abs),'', paste(beta.affirm.multi.abs, stars.affirm.multi.abs,sep=''))
se.affirm.multi.abs<-ifelse(is.na(se.affirm.multi.abs),'',paste('(', se.affirm.multi.abs,')\\ \\ ',sep=''))
affirm.multi.abs<-c(as.vector(rbind(beta.affirm.multi.abs, se.affirm.multi.abs)),formatC(c(n.affirm.multi,n.elite.affirm.multi,n.mass.affirm.multi),big.mark=',',format='d'))

beta.abortion.all.abs<-round(c(test.abortion.all.abs[-1,'Estimate'][c(1:3,6,4:5)],rep(NA,6)),3)
se.abortion.all.abs<-round(c(test.abortion.all.abs[-1,'Std. Error'][c(1:3,6,4:5)],rep(NA,6)),3)
pval.abortion.all.abs<-c(test.abortion.all.abs[-1,'Pr(>|t|)'][c(1:3,6,4:5)],rep(NA,6))
stars.abortion.all.abs<-rep('\\ \\ \\ ',length(beta.abortion.all.abs))
stars.abortion.all.abs[pval.abortion.all.abs <.1]<-'$\\dagger$\\ \\ '
stars.abortion.all.abs[pval.abortion.all.abs <.05]<-'$^*$\\ \\ '
stars.abortion.all.abs[pval.abortion.all.abs <.01]<-'$^{**}$\\ '
stars.abortion.all.abs[pval.abortion.all.abs <.001]<-'$^{***}$'
beta.abortion.all.abs<-ifelse(is.na(beta.abortion.all.abs),'', paste(beta.abortion.all.abs, stars.abortion.all.abs,sep=''))
se.abortion.all.abs<-ifelse(is.na(se.abortion.all.abs),'',paste('(', se.abortion.all.abs,')\\ \\ ',sep=''))
abortion.all.abs<-c(as.vector(rbind(beta.abortion.all.abs, se.abortion.all.abs)),formatC(c(n.abortion.all,n.elite.abortion.all,n.mass.abortion.all),big.mark=',',format='d'))

beta.abortion.multi.abs<-round(c(test.abortion.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.abortion.multi.abs)),'Estimate'][c(1:3,6,4:5,7:12)]),3)
se.abortion.multi.abs<-round(c(test.abortion.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.abortion.multi.abs)),'Std. Error'][c(1:3,6,4:5,7:12)]),3)
pval.abortion.multi.abs<-c(test.abortion.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.abortion.multi.abs)),'Pr(>|t|)'][c(1:3,6,4:5,7:12)])
stars.abortion.multi.abs<-rep('\\ \\ \\ ',length(beta.abortion.multi.abs))
stars.abortion.multi.abs[pval.abortion.multi.abs <.1]<-'$\\dagger$\\ \\ '
stars.abortion.multi.abs[pval.abortion.multi.abs <.05]<-'$^*$\\ \\ '
stars.abortion.multi.abs[pval.abortion.multi.abs <.01]<-'$^{**}$\\ '
stars.abortion.multi.abs[pval.abortion.multi.abs <.001]<-'$^{***}$'
beta.abortion.multi.abs<-ifelse(is.na(beta.abortion.multi.abs),'', paste(beta.abortion.multi.abs, stars.abortion.multi.abs,sep=''))
se.abortion.multi.abs<-ifelse(is.na(se.abortion.multi.abs),'',paste('(', se.abortion.multi.abs,')\\ \\ ',sep=''))
abortion.multi.abs<-c(as.vector(rbind(beta.abortion.multi.abs, se.abortion.multi.abs)),formatC(c(n.abortion.multi,n.elite.abortion.multi,n.mass.abortion.multi),big.mark=',',format='d'))

beta.gaymarriage.all.abs<-round(c(test.gaymarriage.all.abs[-1,'Estimate'][c(1:3,6,4:5)],rep(NA,6)),3)
se.gaymarriage.all.abs<-round(c(test.gaymarriage.all.abs[-1,'Std. Error'][c(1:3,6,4:5)],rep(NA,6)),3)
pval.gaymarriage.all.abs<-c(test.gaymarriage.all.abs[-1,'Pr(>|t|)'][c(1:3,6,4:5)],rep(NA,6))
stars.gaymarriage.all.abs<-rep('\\ \\ \\ ',length(beta.gaymarriage.all.abs))
stars.gaymarriage.all.abs[pval.gaymarriage.all.abs <.1]<-'$\\dagger$\\ \\ '
stars.gaymarriage.all.abs[pval.gaymarriage.all.abs <.05]<-'$^*$\\ \\ '
stars.gaymarriage.all.abs[pval.gaymarriage.all.abs <.01]<-'$^{**}$\\ '
stars.gaymarriage.all.abs[pval.gaymarriage.all.abs <.001]<-'$^{***}$'
beta.gaymarriage.all.abs<-ifelse(is.na(beta.gaymarriage.all.abs),'', paste(beta.gaymarriage.all.abs, stars.gaymarriage.all.abs,sep=''))
se.gaymarriage.all.abs<-ifelse(is.na(se.gaymarriage.all.abs),'',paste('(', se.gaymarriage.all.abs,')\\ \\ ',sep=''))
gaymarriage.all.abs<-c(as.vector(rbind(beta.gaymarriage.all.abs, se.gaymarriage.all.abs)),formatC(c(n.gaymarriage.all,n.elite.gaymarriage.all,n.mass.gaymarriage.all),big.mark=',',format='d'))

beta.gaymarriage.multi.abs<-round(c(test.gaymarriage.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.gaymarriage.multi.abs)),'Estimate'][c(1:3,6,4:5,7:12)]),3)
se.gaymarriage.multi.abs<-round(c(test.gaymarriage.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.gaymarriage.multi.abs)),'Std. Error'][c(1:3,6,4:5,7:12)]),3)
pval.gaymarriage.multi.abs<-c(test.gaymarriage.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.gaymarriage.multi.abs)),'Pr(>|t|)'][c(1:3,6,4:5,7:12)])
stars.gaymarriage.multi.abs<-rep('\\ \\ \\ ',length(beta.gaymarriage.multi.abs))
stars.gaymarriage.multi.abs[pval.gaymarriage.multi.abs <.1]<-'$\\dagger$\\ \\ '
stars.gaymarriage.multi.abs[pval.gaymarriage.multi.abs <.05]<-'$^*$\\ \\ '
stars.gaymarriage.multi.abs[pval.gaymarriage.multi.abs <.01]<-'$^{**}$\\ '
stars.gaymarriage.multi.abs[pval.gaymarriage.multi.abs <.001]<-'$^{***}$'
beta.gaymarriage.multi.abs<-ifelse(is.na(beta.gaymarriage.multi.abs),'', paste(beta.gaymarriage.multi.abs, stars.gaymarriage.multi.abs,sep=''))
se.gaymarriage.multi.abs<-ifelse(is.na(se.gaymarriage.multi.abs),'',paste('(', se.gaymarriage.multi.abs,')\\ \\ ',sep=''))
gaymarriage.multi.abs<-c(as.vector(rbind(beta.gaymarriage.multi.abs, se.gaymarriage.multi.abs)),formatC(c(n.gaymarriage.multi,n.elite.gaymarriage.multi,n.mass.gaymarriage.multi),big.mark=',',format='d'))

beta.classaffirm.all.abs<-round(c(test.classaffirm.all.abs[-1,'Estimate'][c(1:3,6,4:5)],rep(NA,6)),3)
se.classaffirm.all.abs<-round(c(test.classaffirm.all.abs[-1,'Std. Error'][c(1:3,6,4:5)],rep(NA,6)),3)
pval.classaffirm.all.abs<-c(test.classaffirm.all.abs[-1,'Pr(>|t|)'][c(1:3,6,4:5)],rep(NA,6))
stars.classaffirm.all.abs<-rep('\\ \\ \\ ',length(beta.classaffirm.all.abs))
stars.classaffirm.all.abs[pval.classaffirm.all.abs <.1]<-'$\\dagger$\\ \\ '
stars.classaffirm.all.abs[pval.classaffirm.all.abs <.05]<-'$^*$\\ \\ '
stars.classaffirm.all.abs[pval.classaffirm.all.abs <.01]<-'$^{**}$\\ '
stars.classaffirm.all.abs[pval.classaffirm.all.abs <.001]<-'$^{***}$'
beta.classaffirm.all.abs<-ifelse(is.na(beta.classaffirm.all.abs),'', paste(beta.classaffirm.all.abs, stars.classaffirm.all.abs,sep=''))
se.classaffirm.all.abs<-ifelse(is.na(se.classaffirm.all.abs),'',paste('(', se.classaffirm.all.abs,')\\ \\ ',sep=''))
classaffirm.all.abs<-c(as.vector(rbind(beta.classaffirm.all.abs, se.classaffirm.all.abs)),formatC(c(n.classaffirm.all,n.elite.classaffirm.all,n.mass.classaffirm.all),big.mark=',',format='d'))

beta.classaffirm.multi.abs<-round(c(test.classaffirm.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.classaffirm.multi.abs)),'Estimate'][c(1:3,6,4:5,7:12)]),3)
se.classaffirm.multi.abs<-round(c(test.classaffirm.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.classaffirm.multi.abs)),'Std. Error'][c(1:3,6,4:5,7:12)]),3)
pval.classaffirm.multi.abs<-c(test.classaffirm.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.classaffirm.multi.abs)),'Pr(>|t|)'][c(1:3,6,4:5,7:12)])
stars.classaffirm.multi.abs<-rep('\\ \\ \\ ',length(beta.classaffirm.multi.abs))
stars.classaffirm.multi.abs[pval.classaffirm.multi.abs <.1]<-'$\\dagger$\\ \\ '
stars.classaffirm.multi.abs[pval.classaffirm.multi.abs <.05]<-'$^*$\\ \\ '
stars.classaffirm.multi.abs[pval.classaffirm.multi.abs <.01]<-'$^{**}$\\ '
stars.classaffirm.multi.abs[pval.classaffirm.multi.abs <.001]<-'$^{***}$'
beta.classaffirm.multi.abs<-ifelse(is.na(beta.classaffirm.multi.abs),'', paste(beta.classaffirm.multi.abs, stars.classaffirm.multi.abs,sep=''))
se.classaffirm.multi.abs<-ifelse(is.na(se.classaffirm.multi.abs),'',paste('(', se.classaffirm.multi.abs,')\\ \\ ',sep=''))
classaffirm.multi.abs<-c(as.vector(rbind(beta.classaffirm.multi.abs, se.classaffirm.multi.abs)),formatC(c(n.classaffirm.multi,n.elite.classaffirm.multi,n.mass.classaffirm.multi),big.mark=',',format='d'))

beta.environment.all.abs<-round(c(test.environment.all.abs[-1,'Estimate'][c(1:3,6,4:5)],rep(NA,6)),3)
se.environment.all.abs<-round(c(test.environment.all.abs[-1,'Std. Error'][c(1:3,6,4:5)],rep(NA,6)),3)
pval.environment.all.abs<-c(test.environment.all.abs[-1,'Pr(>|t|)'][c(1:3,6,4:5)],rep(NA,6))
stars.environment.all.abs<-rep('\\ \\ \\ ',length(beta.environment.all.abs))
stars.environment.all.abs[pval.environment.all.abs <.1]<-'$\\dagger$\\ \\ '
stars.environment.all.abs[pval.environment.all.abs <.05]<-'$^*$\\ \\ '
stars.environment.all.abs[pval.environment.all.abs <.01]<-'$^{**}$\\ '
stars.environment.all.abs[pval.environment.all.abs <.001]<-'$^{***}$'
beta.environment.all.abs<-ifelse(is.na(beta.environment.all.abs),'', paste(beta.environment.all.abs, stars.environment.all.abs,sep=''))
se.environment.all.abs<-ifelse(is.na(se.environment.all.abs),'',paste('(', se.environment.all.abs,')\\ \\ ',sep=''))
environment.all.abs<-c(as.vector(rbind(beta.environment.all.abs, se.environment.all.abs)),formatC(c(n.environment.all,n.elite.environment.all,n.mass.environment.all),big.mark=',',format='d'))

beta.environment.multi.abs<-round(c(test.environment.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.environment.multi.abs)),'Estimate'][c(1:3,6,4:5,7:12)]),3)
se.environment.multi.abs<-round(c(test.environment.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.environment.multi.abs)),'Std. Error'][c(1:3,6,4:5,7:12)]),3)
pval.environment.multi.abs<-c(test.environment.multi.abs[-1*grep('Intercept|mass_survey',rownames(test.environment.multi.abs)),'Pr(>|t|)'][c(1:3,6,4:5,7:12)])
stars.environment.multi.abs<-rep('\\ \\ \\ ',length(beta.environment.multi.abs))
stars.environment.multi.abs[pval.environment.multi.abs <.1]<-'$\\dagger$\\ \\ '
stars.environment.multi.abs[pval.environment.multi.abs <.05]<-'$^*$\\ \\ '
stars.environment.multi.abs[pval.environment.multi.abs <.01]<-'$^{**}$\\ '
stars.environment.multi.abs[pval.environment.multi.abs <.001]<-'$^{***}$'
beta.environment.multi.abs<-ifelse(is.na(beta.environment.multi.abs),'', paste(beta.environment.multi.abs, stars.environment.multi.abs,sep=''))
se.environment.multi.abs<-ifelse(is.na(se.environment.multi.abs),'',paste('(', se.environment.multi.abs,')\\ \\ ',sep=''))
environment.multi.abs<-c(as.vector(rbind(beta.environment.multi.abs, se.environment.multi.abs)),formatC(c(n.environment.multi,n.elite.environment.multi,n.mass.environment.multi),big.mark=',',format='d'))

bottom.note="NOTE: Dependent variable is the absolute value of the difference in opinion for elite-mass dyads. Entries in parentheses are estimated standard errors, clustered on elite respondent and mass respondent. Intercept and fixed effects for each mass survey estimated but not reported. Observations weighted to correct for disproportionality in legislators' parties and the number of dyads per BLS wave. $\\dagger p < .1$, *$p < .05$, **$p < .01$, ***$p < .001$."

results.table.abs<-cbind(econ.all.abs, econ.multi.abs, econ.noblack.all.abs, econ.noblack.multi.abs, ideol.all.abs, ideol.multi.abs, ideol.noblack.all.abs, ideol.noblack.multi.abs, affirm.all.abs,affirm.multi.abs, classaffirm.all.abs,classaffirm.multi.abs, abortion.all.abs,abortion.multi.abs, gaymarriage.all.abs,gaymarriage.multi.abs, environment.all.abs,environment.multi.abs)
rownames(results.table.abs)<-c('Evangelical','','Female','','No College','','Afro-Brazilian','','Same Party','','Same State','','Age','','News','','Log Muni. Pop.','','Experience','','Corp. Donations','','Clientelism','','$N$','$N$ elites','$N$ masses')
colnames(results.table.abs)<-1:18

results.table.abs.3<-results.table.abs[,(1:9)*2]
colnames(results.table.abs.3)<-c("Econ. Reg.\n'07--'13","Econ. Reg.\n'02--'13","Ideology\n'07--'13","Ideology\n'02--'13",'Race\nQuotas','Class\nQuotas','Abortion','Gay\nMarriage','Environ-\nment')

results.table.abs.4<-results.table.abs[c(1:12,25:27),(1:9)*2-1] # No controls
colnames(results.table.abs.4)<-c("Econ. Reg.\n'07--'13","Econ. Reg.\n'02--'13","Ideology\n'07--'13","Ideology\n'02--'13",'Race\nQuotas','Class\nQuotas','Abortion','Gay\nMarriage','Environ-\nment')

results.table.abs.latex.3<-latex(results.table.abs.3,file='results_table_abs_3_weighted3.tex',collabel.just=rep('c',9),col.just=rep('r',9),rowlabel = '', caption = 'Congruence: WLS Regression Results',rgroup = c('Descriptive Rep.','Traditional Rep.','Mass Controls','Elite Controls','Sample Size'), n.rgroup = c(8,4,6,6,3), extracolsize='small', booktabs = F, ctable = T, where = "htp",insert.bottom=bottom.note,landscape=T)

results.table.abs.latex.4<-latex(results.table.abs.4,file='results_table_abs_4_weighted3.tex',collabel.just=rep('c',9),col.just=rep('r',9),rowlabel = '', caption = 'Congruence: WLS Regression Results (Without Controls)',rgroup = c('Descriptive Rep.','Traditional Rep.','Sample Size'), n.rgroup = c(8,4,3), extracolsize='small', booktabs = F, ctable = T, where = "htp",insert.bottom=bottom.note,landscape=T)

# =======================================================================
# Main Text Figure 2: Opinion Congruence: Effect Comparisons
# Appendix Figure 7: Opinion Congruence: Effect Comparisons (No Controls)
# =======================================================================

coef.diff<-function(test,vc,x1,x2){
	difference<-as.vector(diff(test[c(x2,x1),'Estimate']))
	se<-sqrt(vc[x1,x1]+ vc[x2,x2] - 2*vc[x1,x2])
	pval<-2*(1-pnorm(abs(difference/se)))
	list(difference=difference,se=se,pval=pval)
}

compare.evang.party.econ.all.abs<-coef.diff(test.econ.all.abs,vcov.econ.all.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.econ.all.abs<-coef.diff(test.econ.all.abs,vcov.econ.all.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.econ.all.abs<-coef.diff(test.econ.all.abs,vcov.econ.all.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.econ.all.abs<-coef.diff(test.econ.all.abs,vcov.econ.all.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.econ.all.abs<-coef.diff(test.econ.all.abs,vcov.econ.all.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.econ.all.abs<-coef.diff(test.econ.all.abs,vcov.econ.all.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.econ.all.abs<-coef.diff(test.econ.all.abs,vcov.econ.all.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.econ.all.abs<-coef.diff(test.econ.all.abs,vcov.econ.all.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.econ.multi.abs<-coef.diff(test.econ.multi.abs,vcov.econ.multi.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.econ.multi.abs<-coef.diff(test.econ.multi.abs,vcov.econ.multi.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.econ.multi.abs<-coef.diff(test.econ.multi.abs,vcov.econ.multi.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.econ.multi.abs<-coef.diff(test.econ.multi.abs,vcov.econ.multi.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.econ.multi.abs<-coef.diff(test.econ.multi.abs,vcov.econ.multi.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.econ.multi.abs<-coef.diff(test.econ.multi.abs,vcov.econ.multi.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.econ.multi.abs<-coef.diff(test.econ.multi.abs,vcov.econ.multi.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.econ.multi.abs<-coef.diff(test.econ.multi.abs,vcov.econ.multi.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.econ.noblack.all.abs<-coef.diff(test.econ.noblack.all.abs,vcov.econ.noblack.all.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.econ.noblack.all.abs<-coef.diff(test.econ.noblack.all.abs,vcov.econ.noblack.all.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.econ.noblack.all.abs<-coef.diff(test.econ.noblack.all.abs,vcov.econ.noblack.all.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.evang.state.econ.noblack.all.abs<-coef.diff(test.econ.noblack.all.abs,vcov.econ.noblack.all.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.econ.noblack.all.abs<-coef.diff(test.econ.noblack.all.abs,vcov.econ.noblack.all.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.econ.noblack.all.abs<-coef.diff(test.econ.noblack.all.abs,vcov.econ.noblack.all.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')

compare.evang.party.econ.noblack.multi.abs<-coef.diff(test.econ.noblack.multi.abs,vcov.econ.noblack.multi.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.econ.noblack.multi.abs<-coef.diff(test.econ.noblack.multi.abs,vcov.econ.noblack.multi.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.econ.noblack.multi.abs<-coef.diff(test.econ.noblack.multi.abs,vcov.econ.noblack.multi.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.evang.state.econ.noblack.multi.abs<-coef.diff(test.econ.noblack.multi.abs,vcov.econ.noblack.multi.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.econ.noblack.multi.abs<-coef.diff(test.econ.noblack.multi.abs,vcov.econ.noblack.multi.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.econ.noblack.multi.abs<-coef.diff(test.econ.noblack.multi.abs,vcov.econ.noblack.multi.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')

compare.evang.party.ideol.all.abs<-coef.diff(test.ideol.all.abs,vcov.ideol.all.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.ideol.all.abs<-coef.diff(test.ideol.all.abs,vcov.ideol.all.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.ideol.all.abs<-coef.diff(test.ideol.all.abs,vcov.ideol.all.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.ideol.all.abs<-coef.diff(test.ideol.all.abs,vcov.ideol.all.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.ideol.all.abs<-coef.diff(test.ideol.all.abs,vcov.ideol.all.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.ideol.all.abs<-coef.diff(test.ideol.all.abs,vcov.ideol.all.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.ideol.all.abs<-coef.diff(test.ideol.all.abs,vcov.ideol.all.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.ideol.all.abs<-coef.diff(test.ideol.all.abs,vcov.ideol.all.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.ideol.multi.abs<-coef.diff(test.ideol.multi.abs,vcov.ideol.multi.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.ideol.multi.abs<-coef.diff(test.ideol.multi.abs,vcov.ideol.multi.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.ideol.multi.abs<-coef.diff(test.ideol.multi.abs,vcov.ideol.multi.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.ideol.multi.abs<-coef.diff(test.ideol.multi.abs,vcov.ideol.multi.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.ideol.multi.abs<-coef.diff(test.ideol.multi.abs,vcov.ideol.multi.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.ideol.multi.abs<-coef.diff(test.ideol.multi.abs,vcov.ideol.multi.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.ideol.multi.abs<-coef.diff(test.ideol.multi.abs,vcov.ideol.multi.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.ideol.multi.abs<-coef.diff(test.ideol.multi.abs,vcov.ideol.multi.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.ideol.noblack.all.abs<-coef.diff(test.ideol.noblack.all.abs,vcov.ideol.noblack.all.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.ideol.noblack.all.abs<-coef.diff(test.ideol.noblack.all.abs,vcov.ideol.noblack.all.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.ideol.noblack.all.abs<-coef.diff(test.ideol.noblack.all.abs,vcov.ideol.noblack.all.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.evang.state.ideol.noblack.all.abs<-coef.diff(test.ideol.noblack.all.abs,vcov.ideol.noblack.all.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.ideol.noblack.all.abs<-coef.diff(test.ideol.noblack.all.abs,vcov.ideol.noblack.all.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.ideol.noblack.all.abs<-coef.diff(test.ideol.noblack.all.abs,vcov.ideol.noblack.all.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')

compare.evang.party.ideol.noblack.multi.abs<-coef.diff(test.ideol.noblack.multi.abs,vcov.ideol.noblack.multi.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.ideol.noblack.multi.abs<-coef.diff(test.ideol.noblack.multi.abs,vcov.ideol.noblack.multi.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.ideol.noblack.multi.abs<-coef.diff(test.ideol.noblack.multi.abs,vcov.ideol.noblack.multi.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.evang.state.ideol.noblack.multi.abs<-coef.diff(test.ideol.noblack.multi.abs,vcov.ideol.noblack.multi.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.ideol.noblack.multi.abs<-coef.diff(test.ideol.noblack.multi.abs,vcov.ideol.noblack.multi.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.ideol.noblack.multi.abs<-coef.diff(test.ideol.noblack.multi.abs,vcov.ideol.noblack.multi.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')

compare.evang.party.affirm.all.abs<-coef.diff(test.affirm.all.abs,vcov.affirm.all.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.affirm.all.abs<-coef.diff(test.affirm.all.abs,vcov.affirm.all.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.affirm.all.abs<-coef.diff(test.affirm.all.abs,vcov.affirm.all.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.affirm.all.abs<-coef.diff(test.affirm.all.abs,vcov.affirm.all.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.affirm.all.abs<-coef.diff(test.affirm.all.abs,vcov.affirm.all.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.affirm.all.abs<-coef.diff(test.affirm.all.abs,vcov.affirm.all.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.affirm.all.abs<-coef.diff(test.affirm.all.abs,vcov.affirm.all.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.affirm.all.abs<-coef.diff(test.affirm.all.abs,vcov.affirm.all.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.affirm.multi.abs<-coef.diff(test.affirm.multi.abs,vcov.affirm.multi.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.affirm.multi.abs<-coef.diff(test.affirm.multi.abs,vcov.affirm.multi.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.affirm.multi.abs<-coef.diff(test.affirm.multi.abs,vcov.affirm.multi.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.affirm.multi.abs<-coef.diff(test.affirm.multi.abs,vcov.affirm.multi.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.affirm.multi.abs<-coef.diff(test.affirm.multi.abs,vcov.affirm.multi.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.affirm.multi.abs<-coef.diff(test.affirm.multi.abs,vcov.affirm.multi.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.affirm.multi.abs<-coef.diff(test.affirm.multi.abs,vcov.affirm.multi.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.affirm.multi.abs<-coef.diff(test.affirm.multi.abs,vcov.affirm.multi.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.classaffirm.all.abs<-coef.diff(test.classaffirm.all.abs,vcov.classaffirm.all.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.classaffirm.all.abs<-coef.diff(test.classaffirm.all.abs,vcov.classaffirm.all.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.classaffirm.all.abs<-coef.diff(test.classaffirm.all.abs,vcov.classaffirm.all.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.classaffirm.all.abs<-coef.diff(test.classaffirm.all.abs,vcov.classaffirm.all.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.classaffirm.all.abs<-coef.diff(test.classaffirm.all.abs,vcov.classaffirm.all.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.classaffirm.all.abs<-coef.diff(test.classaffirm.all.abs,vcov.classaffirm.all.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.classaffirm.all.abs<-coef.diff(test.classaffirm.all.abs,vcov.classaffirm.all.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.classaffirm.all.abs<-coef.diff(test.classaffirm.all.abs,vcov.classaffirm.all.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.classaffirm.multi.abs<-coef.diff(test.classaffirm.multi.abs,vcov.classaffirm.multi.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.classaffirm.multi.abs<-coef.diff(test.classaffirm.multi.abs,vcov.classaffirm.multi.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.classaffirm.multi.abs<-coef.diff(test.classaffirm.multi.abs,vcov.classaffirm.multi.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.classaffirm.multi.abs<-coef.diff(test.classaffirm.multi.abs,vcov.classaffirm.multi.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.classaffirm.multi.abs<-coef.diff(test.classaffirm.multi.abs,vcov.classaffirm.multi.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.classaffirm.multi.abs<-coef.diff(test.classaffirm.multi.abs,vcov.classaffirm.multi.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.classaffirm.multi.abs<-coef.diff(test.classaffirm.multi.abs,vcov.classaffirm.multi.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.classaffirm.multi.abs<-coef.diff(test.classaffirm.multi.abs,vcov.classaffirm.multi.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.abortion.all.abs<-coef.diff(test.abortion.all.abs,vcov.abortion.all.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.abortion.all.abs<-coef.diff(test.abortion.all.abs,vcov.abortion.all.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.abortion.all.abs<-coef.diff(test.abortion.all.abs,vcov.abortion.all.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.abortion.all.abs<-coef.diff(test.abortion.all.abs,vcov.abortion.all.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.abortion.all.abs<-coef.diff(test.abortion.all.abs,vcov.abortion.all.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.abortion.all.abs<-coef.diff(test.abortion.all.abs,vcov.abortion.all.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.abortion.all.abs<-coef.diff(test.abortion.all.abs,vcov.abortion.all.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.abortion.all.abs<-coef.diff(test.abortion.all.abs,vcov.abortion.all.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.abortion.multi.abs<-coef.diff(test.abortion.multi.abs,vcov.abortion.multi.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.abortion.multi.abs<-coef.diff(test.abortion.multi.abs,vcov.abortion.multi.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.abortion.multi.abs<-coef.diff(test.abortion.multi.abs,vcov.abortion.multi.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.abortion.multi.abs<-coef.diff(test.abortion.multi.abs,vcov.abortion.multi.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.abortion.multi.abs<-coef.diff(test.abortion.multi.abs,vcov.abortion.multi.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.abortion.multi.abs<-coef.diff(test.abortion.multi.abs,vcov.abortion.multi.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.abortion.multi.abs<-coef.diff(test.abortion.multi.abs,vcov.abortion.multi.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.abortion.multi.abs<-coef.diff(test.abortion.multi.abs,vcov.abortion.multi.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.gaymarriage.all.abs<-coef.diff(test.gaymarriage.all.abs,vcov.gaymarriage.all.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.gaymarriage.all.abs<-coef.diff(test.gaymarriage.all.abs,vcov.gaymarriage.all.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.gaymarriage.all.abs<-coef.diff(test.gaymarriage.all.abs,vcov.gaymarriage.all.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.gaymarriage.all.abs<-coef.diff(test.gaymarriage.all.abs,vcov.gaymarriage.all.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.gaymarriage.all.abs<-coef.diff(test.gaymarriage.all.abs,vcov.gaymarriage.all.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.gaymarriage.all.abs<-coef.diff(test.gaymarriage.all.abs,vcov.gaymarriage.all.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.gaymarriage.all.abs<-coef.diff(test.gaymarriage.all.abs,vcov.gaymarriage.all.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.gaymarriage.all.abs<-coef.diff(test.gaymarriage.all.abs,vcov.gaymarriage.all.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.gaymarriage.multi.abs<-coef.diff(test.gaymarriage.multi.abs,vcov.gaymarriage.multi.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.gaymarriage.multi.abs<-coef.diff(test.gaymarriage.multi.abs,vcov.gaymarriage.multi.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.gaymarriage.multi.abs<-coef.diff(test.gaymarriage.multi.abs,vcov.gaymarriage.multi.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.gaymarriage.multi.abs<-coef.diff(test.gaymarriage.multi.abs,vcov.gaymarriage.multi.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.gaymarriage.multi.abs<-coef.diff(test.gaymarriage.multi.abs,vcov.gaymarriage.multi.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.gaymarriage.multi.abs<-coef.diff(test.gaymarriage.multi.abs,vcov.gaymarriage.multi.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.gaymarriage.multi.abs<-coef.diff(test.gaymarriage.multi.abs,vcov.gaymarriage.multi.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.gaymarriage.multi.abs<-coef.diff(test.gaymarriage.multi.abs,vcov.gaymarriage.multi.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.environment.all.abs<-coef.diff(test.environment.all.abs,vcov.environment.all.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.environment.all.abs<-coef.diff(test.environment.all.abs,vcov.environment.all.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.environment.all.abs<-coef.diff(test.environment.all.abs,vcov.environment.all.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.environment.all.abs<-coef.diff(test.environment.all.abs,vcov.environment.all.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.environment.all.abs<-coef.diff(test.environment.all.abs,vcov.environment.all.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.environment.all.abs<-coef.diff(test.environment.all.abs,vcov.environment.all.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.environment.all.abs<-coef.diff(test.environment.all.abs,vcov.environment.all.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.environment.all.abs<-coef.diff(test.environment.all.abs,vcov.environment.all.abs,'I(elite_black * mass_black)','state_matchTRUE')

compare.evang.party.environment.multi.abs<-coef.diff(test.environment.multi.abs,vcov.environment.multi.abs,'I(elite_evang * mass_evang)','party_matchTRUE')
compare.female.party.environment.multi.abs<-coef.diff(test.environment.multi.abs,vcov.environment.multi.abs,'I(elite_female * mass_female)','party_matchTRUE')
compare.loweduc.party.environment.multi.abs<-coef.diff(test.environment.multi.abs,vcov.environment.multi.abs,'I(elite_loweduc * mass_loweduc)','party_matchTRUE')
compare.black.party.environment.multi.abs<-coef.diff(test.environment.multi.abs,vcov.environment.multi.abs,'I(elite_black * mass_black)','party_matchTRUE')
compare.evang.state.environment.multi.abs<-coef.diff(test.environment.multi.abs,vcov.environment.multi.abs,'I(elite_evang * mass_evang)','state_matchTRUE')
compare.female.state.environment.multi.abs<-coef.diff(test.environment.multi.abs,vcov.environment.multi.abs,'I(elite_female * mass_female)','state_matchTRUE')
compare.loweduc.state.environment.multi.abs<-coef.diff(test.environment.multi.abs,vcov.environment.multi.abs,'I(elite_loweduc * mass_loweduc)','state_matchTRUE')
compare.black.state.environment.multi.abs<-coef.diff(test.environment.multi.abs,vcov.environment.multi.abs,'I(elite_black * mass_black)','state_matchTRUE')

# Dot-plot of effect comparisons

plot.data.multi.abs<-data.frame(
	estimate=c(compare.evang.party.econ.multi.abs$difference, compare.female.party.econ.multi.abs$difference, compare.loweduc.party.econ.multi.abs$difference, compare.black.party.econ.multi.abs$difference, compare.evang.state.econ.multi.abs$difference, compare.female.state.econ.multi.abs$difference, compare.loweduc.state.econ.multi.abs$difference, compare.black.state.econ.multi.abs$difference, 
	compare.evang.party.econ.noblack.multi.abs$difference, compare.female.party.econ.noblack.multi.abs$difference, compare.loweduc.party.econ.noblack.multi.abs$difference, NA, compare.evang.state.econ.noblack.multi.abs$difference, compare.female.state.econ.noblack.multi.abs$difference, compare.loweduc.state.econ.noblack.multi.abs$difference, NA, 
	compare.evang.party.ideol.multi.abs$difference, compare.female.party.ideol.multi.abs$difference, compare.loweduc.party.ideol.multi.abs$difference, compare.black.party.ideol.multi.abs$difference, compare.evang.state.ideol.multi.abs$difference, compare.female.state.ideol.multi.abs$difference, compare.loweduc.state.ideol.multi.abs$difference, compare.black.state.ideol.multi.abs$difference, 
	compare.evang.party.ideol.noblack.multi.abs$difference, compare.female.party.ideol.noblack.multi.abs$difference, compare.loweduc.party.ideol.noblack.multi.abs$difference, NA, compare.evang.state.ideol.noblack.multi.abs$difference, compare.female.state.ideol.noblack.multi.abs$difference, compare.loweduc.state.ideol.noblack.multi.abs$difference, NA, 
	# compare.evang.party.auth.multi.abs$difference, compare.female.party.auth.multi.abs$difference, compare.loweduc.party.auth.multi.abs$difference, NA, compare.evang.state.auth.multi.abs$difference, compare.female.state.auth.multi.abs$difference, compare.loweduc.state.auth.multi.abs$difference, NA, 
	compare.evang.party.affirm.multi.abs$difference, compare.female.party.affirm.multi.abs$difference, compare.loweduc.party.affirm.multi.abs$difference, compare.black.party.affirm.multi.abs$difference, compare.evang.state.affirm.multi.abs$difference, compare.female.state.affirm.multi.abs$difference, compare.loweduc.state.affirm.multi.abs$difference, compare.black.state.affirm.multi.abs$difference, 
	compare.evang.party.classaffirm.multi.abs$difference, compare.female.party.classaffirm.multi.abs$difference, compare.loweduc.party.classaffirm.multi.abs$difference, compare.black.party.classaffirm.multi.abs$difference, compare.evang.state.classaffirm.multi.abs$difference, compare.female.state.classaffirm.multi.abs$difference, compare.loweduc.state.classaffirm.multi.abs$difference, compare.black.state.classaffirm.multi.abs$difference, 
	compare.evang.party.abortion.multi.abs$difference, compare.female.party.abortion.multi.abs$difference, compare.loweduc.party.abortion.multi.abs$difference, compare.black.party.abortion.multi.abs$difference, compare.evang.state.abortion.multi.abs$difference, compare.female.state.abortion.multi.abs$difference, compare.loweduc.state.abortion.multi.abs$difference, compare.black.state.abortion.multi.abs$difference, 
	compare.evang.party.gaymarriage.multi.abs$difference, compare.female.party.gaymarriage.multi.abs$difference, compare.loweduc.party.gaymarriage.multi.abs$difference, compare.black.party.gaymarriage.multi.abs$difference, compare.evang.state.gaymarriage.multi.abs$difference, compare.female.state.gaymarriage.multi.abs$difference, compare.loweduc.state.gaymarriage.multi.abs$difference, compare.black.state.gaymarriage.multi.abs$difference, 
	compare.evang.party.environment.multi.abs$difference, compare.female.party.environment.multi.abs$difference, compare.loweduc.party.environment.multi.abs$difference, compare.black.party.environment.multi.abs$difference, compare.evang.state.environment.multi.abs$difference, compare.female.state.environment.multi.abs$difference, compare.loweduc.state.environment.multi.abs$difference, compare.black.state.environment.multi.abs$difference),
se=c(compare.evang.party.econ.multi.abs$se, compare.female.party.econ.multi.abs$se, compare.loweduc.party.econ.multi.abs$se, compare.black.party.econ.multi.abs$se, compare.evang.state.econ.multi.abs$se, compare.female.state.econ.multi.abs$se, compare.loweduc.state.econ.multi.abs$se, compare.black.state.econ.multi.abs$se, 
	compare.evang.party.econ.noblack.multi.abs$se, compare.female.party.econ.noblack.multi.abs$se, compare.loweduc.party.econ.noblack.multi.abs$se, NA, compare.evang.state.econ.noblack.multi.abs$se, compare.female.state.econ.noblack.multi.abs$se, compare.loweduc.state.econ.noblack.multi.abs$se, NA, 
	compare.evang.party.ideol.multi.abs$se, compare.female.party.ideol.multi.abs$se, compare.loweduc.party.ideol.multi.abs$se, compare.black.party.ideol.multi.abs$se, compare.evang.state.ideol.multi.abs$se, compare.female.state.ideol.multi.abs$se, compare.loweduc.state.ideol.multi.abs$se, compare.black.state.ideol.multi.abs$se, 
	compare.evang.party.ideol.noblack.multi.abs$se, compare.female.party.ideol.noblack.multi.abs$se, compare.loweduc.party.ideol.noblack.multi.abs$se, NA, compare.evang.state.ideol.noblack.multi.abs$se, compare.female.state.ideol.noblack.multi.abs$se, compare.loweduc.state.ideol.noblack.multi.abs$se, NA, 
	compare.evang.party.affirm.multi.abs$se, compare.female.party.affirm.multi.abs$se, compare.loweduc.party.affirm.multi.abs$se, compare.black.party.affirm.multi.abs$se, compare.evang.state.affirm.multi.abs$se, compare.female.state.affirm.multi.abs$se, compare.loweduc.state.affirm.multi.abs$se, compare.black.state.affirm.multi.abs$se, 
	compare.evang.party.classaffirm.multi.abs$se, compare.female.party.classaffirm.multi.abs$se, compare.loweduc.party.classaffirm.multi.abs$se, compare.black.party.classaffirm.multi.abs$se, compare.evang.state.classaffirm.multi.abs$se, compare.female.state.classaffirm.multi.abs$se, compare.loweduc.state.classaffirm.multi.abs$se, compare.black.state.classaffirm.multi.abs$se, 
	compare.evang.party.abortion.multi.abs$se, compare.female.party.abortion.multi.abs$se, compare.loweduc.party.abortion.multi.abs$se, compare.black.party.abortion.multi.abs$se, compare.evang.state.abortion.multi.abs$se, compare.female.state.abortion.multi.abs$se, compare.loweduc.state.abortion.multi.abs$se, compare.black.state.abortion.multi.abs$se, 
	compare.evang.party.gaymarriage.multi.abs$se, compare.female.party.gaymarriage.multi.abs$se, compare.loweduc.party.gaymarriage.multi.abs$se, compare.black.party.gaymarriage.multi.abs$se, compare.evang.state.gaymarriage.multi.abs$se, compare.female.state.gaymarriage.multi.abs$se, compare.loweduc.state.gaymarriage.multi.abs$se, compare.black.state.gaymarriage.multi.abs$se, 
	compare.evang.party.environment.multi.abs$se, compare.female.party.environment.multi.abs$se, compare.loweduc.party.environment.multi.abs$se, compare.black.party.environment.multi.abs$se, compare.evang.state.environment.multi.abs$se, compare.female.state.environment.multi.abs$se, compare.loweduc.state.environment.multi.abs$se, compare.black.state.environment.multi.abs$se),
	issue=factor(c(rep("Econ. Reg. 07-13",8), rep("Econ. Reg. 02-13",8), rep("Ideology 07-13",8), rep("Ideology 02-13",8), rep('Race Quotas',8), rep('Class Quotas',8), rep('Abortion',8),rep('Gay Marriage',8), rep('Environment',8)), levels=c("Econ. Reg. 07-13","Econ. Reg. 02-13","Ideology 07-13","Ideology 02-13",'Political Regime','Race Quotas','Class Quotas','Abortion','Gay Marriage','Environment')),
	comparison=factor(rep(c('Evangelicals - Party','Women - Party','No College - Party','Afro-Brazilians - Party','Evangelicals - State','Women - State','No College - State','Afro-Brazilians - State'),9),levels=rev(c('Evangelicals - Party','Women - Party','No College - Party','Afro-Brazilians - Party','Evangelicals - State','Women - State','No College - State','Afro-Brazilians - State'))))
plot.data.multi.abs$min90<-plot.data.multi.abs$estimate - qnorm(.95)* plot.data.multi.abs$se
plot.data.multi.abs$max90<-plot.data.multi.abs$estimate + qnorm(.95)* plot.data.multi.abs$se
plot.data.multi.abs$min95<-plot.data.multi.abs$estimate - qnorm(.975)* plot.data.multi.abs$se
plot.data.multi.abs$max95<-plot.data.multi.abs$estimate + qnorm(.975)* plot.data.multi.abs$se
plot.data.multi.abs$sig10<-plot.data.multi.abs$min90* plot.data.multi.abs$max90 > 0
plot.data.multi.abs$sig05<-plot.data.multi.abs$min95* plot.data.multi.abs$max95 > 0

pdf(file='effect_comparison_weighted3.pdf',width=10,height=7.5)
with(plot.data.multi.abs,dotplot(comparison~estimate | issue, as.table=T,par.settings=standard.theme(color=F), xlim=c(-.37,.37),main='',xlab=list(label=expression(paste('Difference in ',hat(beta),' (point estimates and 95% confidence intervals)',sep='')),cex=1),scales=list(cex=1),layout=c(5,2),panel=function(x,y,subscripts) {
	panel.dotplot(x,y,pch=1,cex=1.25)
	panel.points(ifelse(sig05[subscripts],estimate[subscripts],NA),y, pch=19, cex=1.25)
	panel.segments(min95[subscripts],as.numeric(y),max95[subscripts], as.numeric(y),lwd=1.5)
	panel.abline(v=0,lty=2,lwd=1.5)
	}
	))
dev.off()

plot.data.all.abs<-data.frame(
	estimate=c(compare.evang.party.econ.all.abs$difference, compare.female.party.econ.all.abs$difference, compare.loweduc.party.econ.all.abs$difference, compare.black.party.econ.all.abs$difference, compare.evang.state.econ.all.abs$difference, compare.female.state.econ.all.abs$difference, compare.loweduc.state.econ.all.abs$difference, compare.black.state.econ.all.abs$difference, 
	compare.evang.party.econ.noblack.all.abs$difference, compare.female.party.econ.noblack.all.abs$difference, compare.loweduc.party.econ.noblack.all.abs$difference, NA, compare.evang.state.econ.noblack.all.abs$difference, compare.female.state.econ.noblack.all.abs$difference, compare.loweduc.state.econ.noblack.all.abs$difference, NA, 
	compare.evang.party.ideol.all.abs$difference, compare.female.party.ideol.all.abs$difference, compare.loweduc.party.ideol.all.abs$difference, compare.black.party.ideol.all.abs$difference, compare.evang.state.ideol.all.abs$difference, compare.female.state.ideol.all.abs$difference, compare.loweduc.state.ideol.all.abs$difference, compare.black.state.ideol.all.abs$difference, 
	compare.evang.party.ideol.noblack.all.abs$difference, compare.female.party.ideol.noblack.all.abs$difference, compare.loweduc.party.ideol.noblack.all.abs$difference, NA, compare.evang.state.ideol.noblack.all.abs$difference, compare.female.state.ideol.noblack.all.abs$difference, compare.loweduc.state.ideol.noblack.all.abs$difference, NA, 
	compare.evang.party.affirm.all.abs$difference, compare.female.party.affirm.all.abs$difference, compare.loweduc.party.affirm.all.abs$difference, compare.black.party.affirm.all.abs$difference, compare.evang.state.affirm.all.abs$difference, compare.female.state.affirm.all.abs$difference, compare.loweduc.state.affirm.all.abs$difference, compare.black.state.affirm.all.abs$difference, 
	compare.evang.party.classaffirm.all.abs$difference, compare.female.party.classaffirm.all.abs$difference, compare.loweduc.party.classaffirm.all.abs$difference, compare.black.party.classaffirm.all.abs$difference, compare.evang.state.classaffirm.all.abs$difference, compare.female.state.classaffirm.all.abs$difference, compare.loweduc.state.classaffirm.all.abs$difference, compare.black.state.classaffirm.all.abs$difference, 
	compare.evang.party.abortion.all.abs$difference, compare.female.party.abortion.all.abs$difference, compare.loweduc.party.abortion.all.abs$difference, compare.black.party.abortion.all.abs$difference, compare.evang.state.abortion.all.abs$difference, compare.female.state.abortion.all.abs$difference, compare.loweduc.state.abortion.all.abs$difference, compare.black.state.abortion.all.abs$difference, 
	compare.evang.party.gaymarriage.all.abs$difference, compare.female.party.gaymarriage.all.abs$difference, compare.loweduc.party.gaymarriage.all.abs$difference, compare.black.party.gaymarriage.all.abs$difference, compare.evang.state.gaymarriage.all.abs$difference, compare.female.state.gaymarriage.all.abs$difference, compare.loweduc.state.gaymarriage.all.abs$difference, compare.black.state.gaymarriage.all.abs$difference, 
	compare.evang.party.environment.all.abs$difference, compare.female.party.environment.all.abs$difference, compare.loweduc.party.environment.all.abs$difference, compare.black.party.environment.all.abs$difference, compare.evang.state.environment.all.abs$difference, compare.female.state.environment.all.abs$difference, compare.loweduc.state.environment.all.abs$difference, compare.black.state.environment.all.abs$difference),
se=c(compare.evang.party.econ.all.abs$se, compare.female.party.econ.all.abs$se, compare.loweduc.party.econ.all.abs$se, compare.black.party.econ.all.abs$se, compare.evang.state.econ.all.abs$se, compare.female.state.econ.all.abs$se, compare.loweduc.state.econ.all.abs$se, compare.black.state.econ.all.abs$se, 
	compare.evang.party.econ.noblack.all.abs$se, compare.female.party.econ.noblack.all.abs$se, compare.loweduc.party.econ.noblack.all.abs$se, NA, compare.evang.state.econ.noblack.all.abs$se, compare.female.state.econ.noblack.all.abs$se, compare.loweduc.state.econ.noblack.all.abs$se, NA, 
	compare.evang.party.ideol.all.abs$se, compare.female.party.ideol.all.abs$se, compare.loweduc.party.ideol.all.abs$se, compare.black.party.ideol.all.abs$se, compare.evang.state.ideol.all.abs$se, compare.female.state.ideol.all.abs$se, compare.loweduc.state.ideol.all.abs$se, compare.black.state.ideol.all.abs$se, 
	compare.evang.party.ideol.noblack.all.abs$se, compare.female.party.ideol.noblack.all.abs$se, compare.loweduc.party.ideol.noblack.all.abs$se, NA, compare.evang.state.ideol.noblack.all.abs$se, compare.female.state.ideol.noblack.all.abs$se, compare.loweduc.state.ideol.noblack.all.abs$se, NA, 
	compare.evang.party.affirm.all.abs$se, compare.female.party.affirm.all.abs$se, compare.loweduc.party.affirm.all.abs$se, compare.black.party.affirm.all.abs$se, compare.evang.state.affirm.all.abs$se, compare.female.state.affirm.all.abs$se, compare.loweduc.state.affirm.all.abs$se, compare.black.state.affirm.all.abs$se, 
	compare.evang.party.classaffirm.all.abs$se, compare.female.party.classaffirm.all.abs$se, compare.loweduc.party.classaffirm.all.abs$se, compare.black.party.classaffirm.all.abs$se, compare.evang.state.classaffirm.all.abs$se, compare.female.state.classaffirm.all.abs$se, compare.loweduc.state.classaffirm.all.abs$se, compare.black.state.classaffirm.all.abs$se, 
	compare.evang.party.abortion.all.abs$se, compare.female.party.abortion.all.abs$se, compare.loweduc.party.abortion.all.abs$se, compare.black.party.abortion.all.abs$se, compare.evang.state.abortion.all.abs$se, compare.female.state.abortion.all.abs$se, compare.loweduc.state.abortion.all.abs$se, compare.black.state.abortion.all.abs$se, 
	compare.evang.party.gaymarriage.all.abs$se, compare.female.party.gaymarriage.all.abs$se, compare.loweduc.party.gaymarriage.all.abs$se, compare.black.party.gaymarriage.all.abs$se, compare.evang.state.gaymarriage.all.abs$se, compare.female.state.gaymarriage.all.abs$se, compare.loweduc.state.gaymarriage.all.abs$se, compare.black.state.gaymarriage.all.abs$se, 
	compare.evang.party.environment.all.abs$se, compare.female.party.environment.all.abs$se, compare.loweduc.party.environment.all.abs$se, compare.black.party.environment.all.abs$se, compare.evang.state.environment.all.abs$se, compare.female.state.environment.all.abs$se, compare.loweduc.state.environment.all.abs$se, compare.black.state.environment.all.abs$se),
	issue=factor(c(rep("Econ. Reg. 07-13",8), rep("Econ. Reg. 02-13",8), rep("Ideology 07-13",8), rep("Ideology 02-13",8), rep('Race Quotas',8), rep('Class Quotas',8), rep('Abortion',8),rep('Gay Marriage',8), rep('Environment',8)), levels=c("Econ. Reg. 07-13","Econ. Reg. 02-13","Ideology 07-13","Ideology 02-13",'Political Regime','Race Quotas','Class Quotas','Abortion','Gay Marriage','Environment')),
	comparison=factor(rep(c('Evangelicals - Party','Women - Party','No College - Party','Afro-Brazilians - Party','Evangelicals - State','Women - State','No College - State','Afro-Brazilians - State'),9),levels=rev(c('Evangelicals - Party','Women - Party','No College - Party','Afro-Brazilians - Party','Evangelicals - State','Women - State','No College - State','Afro-Brazilians - State'))))
plot.data.all.abs$min90<-plot.data.all.abs$estimate - qnorm(.95)* plot.data.all.abs$se
plot.data.all.abs$max90<-plot.data.all.abs$estimate + qnorm(.95)* plot.data.all.abs$se
plot.data.all.abs$min95<-plot.data.all.abs$estimate - qnorm(.975)* plot.data.all.abs$se
plot.data.all.abs$max95<-plot.data.all.abs$estimate + qnorm(.975)* plot.data.all.abs$se
plot.data.all.abs$sig10<-plot.data.all.abs$min90* plot.data.all.abs$max90 > 0
plot.data.all.abs$sig05<-plot.data.all.abs$min95* plot.data.all.abs$max95 > 0

pdf(file='effect_comparison_nocontrols_weighted3.pdf',width=10,height=7.5)
with(plot.data.all.abs,dotplot(comparison~estimate | issue, as.table=T,par.settings=standard.theme(color=F), xlim=c(-.37,.37),main='',xlab=list(label=expression(paste('Difference in ',hat(beta),' (point estimates and 95% confidence intervals)',sep='')),cex=1), scales=list(cex=1),layout=c(5,2),panel=function(x,y,subscripts) {
	panel.dotplot(x,y,pch=1,cex=1.25)
	panel.points(ifelse(sig05[subscripts],estimate[subscripts],NA),y, pch=19, cex=1.25)
	panel.segments(min95[subscripts],as.numeric(y),max95[subscripts], as.numeric(y),lwd=1.5)
	panel.abline(v=0,lty=2,lwd=1.5)
	}
	))
dev.off()

# ==========================
# Results Conveyed Textually 
# ==========================

# "For both abortion and gay marriage, evangelical legislators and citizens are about half a standard deviation closer to one another than elites and masses of the same party, and about a third of a standard deviation closer than those from the same state. For ideology, they are about one-quarter and one-seventh of a standard deviation closer, respectively."

# NOTE: This statement in the text is not quite accurate. When preparing the replication archive, we discovered a small error that was causing us to underestimate the magnitude of some effects. The corrected code is below. It was too late to change the text in the published article. A more accurate statement (changes in all caps) would be:

# "For both abortion and gay marriage, evangelical legislators and citizens are AT LEAST half a standard deviation closer to one another than elites and masses of the same party, and AT LEAST a third of a standard deviation closer than those from the same state. For ideology, they are about FOUR-TENTHS and ONE-QUARTER of a standard deviation closer, respectively.

load('dyads.RData')

plot.data.multi.abs[plot.data.multi.abs$comparison == 'Evangelicals - Party' & plot.data.multi.abs$issue=='Gay Marriage','estimate'] / sd(abs(dyads$mass_gaymarriage - dyads$elite_gaymarriage),na.rm=T)

plot.data.multi.abs[plot.data.multi.abs$comparison == 'Evangelicals - Party' & plot.data.multi.abs$issue=='Abortion','estimate'] / sd(abs(dyads$mass_abortion - dyads$elite_abortion),na.rm=T)

plot.data.multi.abs[plot.data.multi.abs$comparison == 'Evangelicals - State' & plot.data.multi.abs$issue=='Gay Marriage','estimate'] / sd(abs(dyads$mass_gaymarriage - dyads$elite_gaymarriage),na.rm=T)

plot.data.multi.abs[plot.data.multi.abs$comparison == 'Evangelicals - State' & plot.data.multi.abs$issue=='Abortion','estimate'] / sd(abs(dyads$mass_abortion - dyads$elite_abortion),na.rm=T)

plot.data.multi.abs[plot.data.multi.abs$comparison == 'Evangelicals - Party' & plot.data.multi.abs$issue=='Ideology 02-13','estimate'] / sd(abs(dyads$mass_ideol - dyads$elite_ideol),na.rm=T)

plot.data.multi.abs[plot.data.multi.abs$comparison == 'Evangelicals - State' & plot.data.multi.abs$issue=='Ideology 02-13','estimate'] / sd(abs(dyads$mass_ideol - dyads$elite_ideol),na.rm=T)


